package com.sxm.yiwei.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.sxm.yiwei.R;
import com.sxm.yiwei.activitis.CryHopeResultActivity;
import com.sxm.yiwei.utils.InternetAddressUtis;

import org.xutils.x;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * Created by KuKa on 2017/6/5.
 * 心愿结果列表
 */

public class ResultHopeAdapter extends BaseAdapter {
    private Context context;
    private List<HashMap<String, String>> dataList;
    public ResultHopeAdapter(Context context, List<HashMap<String, String>> dataList) {
        this.context=context;
        this.dataList=dataList;
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        ViewHolder holder;
        if (convertView==null){
            view = View.inflate(context,R.layout.result_litem,null);
            holder = new ViewHolder();
            holder.resulthead = (ImageView) view.findViewById(R.id.result_head);
            holder.resultmoney = (TextView) view.findViewById(R.id.result_money);
            holder.resultname = (TextView) view.findViewById(R.id.result_name);
            holder.result_wish = (TextView) view.findViewById(R.id.result_wish);
            holder.resulttime = (TextView) view.findViewById(R.id.result_time);
            view.setTag(holder);
        }else {
            view=convertView;
            holder = (ViewHolder) view.getTag();
        }
        Date date = new Date(Long.valueOf(dataList.get(position).get("createTime")));
        SimpleDateFormat s = new SimpleDateFormat("MM/dd HH:mm");
        String format = s.format(date);
        holder.resultname.setText(dataList.get(position).get("nickname"));
        holder.resultmoney.setText(dataList.get(position).get("amount"));
        holder.resulttime.setText(format);
        holder.result_wish.setText(dataList.get(position).get("wish"));
        x.image().bind(holder.resulthead, InternetAddressUtis.IMG_URL+dataList.get(position).get("avatar"));

        return view;
    }

   public class ViewHolder{
        private TextView resultname,resulttime,resultmoney,result_wish;
        private ImageView resulthead;
    }

}
